//////////////////////////////////////////////////////////////////////////
// triface - class to hold information about triangular face
// By Antonio Miranda - October 2010
//////////////////////////////////////////////////////////////////////////

#ifndef _BD3D_FACE_
#define _BD3D_FACE_

#include <vector>

#include "box3d.h"
#include "blockalloc.h"


using namespace std;

class node;
//
//////////////////////////////////////////////////////////////////////////
class triface
{
public:
  triface(void);
  ~triface(void);

  // vertex
  int vert[3];
  int sort_vert[3];

  // adj elements
  int adjElem[2];

  // attributes
  Box3D  box;
  double r_x_s[3];
  double area;
  double center[3];

  // flags
  int use;
  int key;

  int layer;
  int frac;

  bool boundary;

  // flag to indicate that the face must be removed to face list
  bool removed;


  // add vertex
  void addVertex (int i, int j, int k, vector <node *> &nodes);

  // get box
  void getBox (double &xmin_, double &ymin_, double &zmin_,
               double &xmax_, double &ymax_, double &zmax_);

  // perpendicular distance to point
  double distToPoint   (double pts[3]);
  bool   isPointAbove  (double pts[3]);
  bool   isPointBellow (double pts[3]);

  // solid angle
  double solidAngle (double pts[3], vector <node *> &nodes);

  double volume (double pts[3], vector <node *> &nodes);

  double Srms (double pts[3], vector <node *> &nodes);

  // characteristic size
  double size ( );

  // print
  void print ( );

  // print nodes
  void printNodes ( );


private:

  // sort vertex's to sort_vert
  void sort ( );

  double solidEdge  (double a[3], double b[3], double r1[3], double r_x_s[3]);

  double volumeFace (double v1[3], double v2[3], double v3[3]);

  double SrmsEdge (double v1[3], double v2[3]);
};


#endif



